using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWTSTR
    {
        public DataRow Convert2WTSTR(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWTSTR(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WTIMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WTIKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WTIWERK"] = " ".PadRight(3 ); 
         dwReturn["WTIABT"] = " ".PadRight(3 ); 
         dwReturn["WTIART"] = " ".PadRight(20 ); 
         dwReturn["WTIVAR"] = " ".PadRight(2 ); 
         dwReturn["WTIAENZL"] = " ".PadRight(0 ); 
         dwReturn["WTIAENB"] = " ".PadRight(8 ); 
         dwReturn["WTIAEND"] = " ".PadRight(0 ); 
         dwReturn["WTINEUB"] = " ".PadRight(8 ); 
         dwReturn["WTINEUD"] = " ".PadRight(0 ); 
         dwReturn["WTIPATRNR"] = " ".PadRight(15 ); 
         dwReturn["WTIAUFSTECK"] = " ".PadRight(8 ); 
         dwReturn["WTIBINDG"] = " ".PadRight(15 ); 
         dwReturn["WTIDEHNQ"] = " ".PadRight(0 ); 
         dwReturn["WTIDEHNL"] = " ".PadRight(0 ); 
         dwReturn["WTIRIPPSCHH"] = " ".PadRight(0 ); 
         dwReturn["WTIPRUEFM"] = " ".PadRight(8 ); 
         dwReturn["WTINAZAHL"] = " ".PadRight(0 ); 
         dwReturn["WTIFEINH"] = " ".PadRight(0 ); 
         dwReturn["WTIFEINHGE"] = " ".PadRight(1 ); 
         dwReturn["WTIABRT"] = " ".PadRight(0 ); 
         dwReturn["WTIWICKBRT"] = " ".PadRight(0 ); 
         dwReturn["WTIARBSYS"] = " ".PadRight(0 ); 
         dwReturn["WTITOURSTK"] = " ".PadRight(0 ); 
         dwReturn["WTIRWBRT"] = " ".PadRight(0 ); 
         dwReturn["WTIRWGEWQM"] = " ".PadRight(0 ); 
         dwReturn["WTIRWGEWLFD"] = " ".PadRight(0 ); 
         dwReturn["WTIRWMADI"] = " ".PadRight(0 ); 
         dwReturn["WTIRWMADIM"] = " ".PadRight(3 ); 
         dwReturn["WTIRWMADIF"] = " ".PadRight(12 ); 
         dwReturn["WTIRWFDDI"] = " ".PadRight(0 ); 
         dwReturn["WTIRWFDDIM"] = " ".PadRight(3 ); 
         dwReturn["WTIRWFDDIF"] = " ".PadRight(12 ); 
         dwReturn["WTIRWGVERB"] = " ".PadRight(0 ); 
         dwReturn["WTIAGBRT"] = " ".PadRight(0 ); 
         dwReturn["WTIAGGEWQM"] = " ".PadRight(0 ); 
         dwReturn["WTIAGGEWLFD"] = " ".PadRight(0 ); 
         dwReturn["WTIAGMADI"] = " ".PadRight(0 ); 
         dwReturn["WTIAGMADIM"] = " ".PadRight(3 ); 
         dwReturn["WTIAGMADIF"] = " ".PadRight(12 ); 
         dwReturn["WTIAGFDDI"] = " ".PadRight(0 ); 
         dwReturn["WTIAGFDDIM"] = " ".PadRight(3 ); 
         dwReturn["WTIAGFDDIF"] = " ".PadRight(12 ); 
         dwReturn["WTIAGGVERB"] = " ".PadRight(0 ); 
         dwReturn["WTIPGEWLFD"] = " ".PadRight(0 ); 
         dwReturn["WTIPGEWQM"] = " ".PadRight(0 ); 
         dwReturn["WTIABWPGEW"] = " ".PadRight(0 ); 
         dwReturn["WTIUEBGEW"] = " ".PadRight(1 ); 
         dwReturn["WTIPMADI"] = " ".PadRight(0 ); 
         dwReturn["WTIPMADIM"] = " ".PadRight(3 ); 
         dwReturn["WTIPMADIF"] = " ".PadRight(12 ); 
         dwReturn["WTIABWPMADI"] = " ".PadRight(0 ); 
         dwReturn["WTIUEBMADI"] = " ".PadRight(1 ); 
         dwReturn["WTIFILLER"] = " ".PadRight(54 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWTSTR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWTSTR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTSTR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWTSTR(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWTSTR(dwLocal, ITXDBVERSION);
            }
            UpdateWTSTR(dwLocal);
        }
        public void InsertWTSTR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WTSTR(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWTSTR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WTSTR WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WTSTR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WTSTR";
            Return = Result;
            return Return;
        }
        public void DeleteWTSTR(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WTSTR   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWTSTR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WTSTR SET "
                    +"WTIMANDANT= :WTIMANDANT,"
                    +"WTIKUNDNR= :WTIKUNDNR,"
                    +"WTIWERK= :WTIWERK,"
                    +"WTIABT= :WTIABT,"
                    +"WTIART= :WTIART,"
                    +"WTIVAR= :WTIVAR,"
                    +"WTIAENZL= :WTIAENZL,"
                    +"WTIAENB= :WTIAENB,"
                    +"WTIAEND= :WTIAEND,"
                    +"WTINEUB= :WTINEUB,"
                    +"WTINEUD= :WTINEUD,"
                    +"WTIPATRNR= :WTIPATRNR,"
                    +"WTIAUFSTECK= :WTIAUFSTECK,"
                    +"WTIBINDG= :WTIBINDG,"
                    +"WTIDEHNQ= :WTIDEHNQ,"
                    +"WTIDEHNL= :WTIDEHNL,"
                    +"WTIRIPPSCHH= :WTIRIPPSCHH,"
                    +"WTIPRUEFM= :WTIPRUEFM,"
                    +"WTINAZAHL= :WTINAZAHL,"
                    +"WTIFEINH= :WTIFEINH,"
                    +"WTIFEINHGE= :WTIFEINHGE,"
                    +"WTIABRT= :WTIABRT,"
                    +"WTIWICKBRT= :WTIWICKBRT,"
                    +"WTIARBSYS= :WTIARBSYS,"
                    +"WTITOURSTK= :WTITOURSTK,"
                    +"WTIRWBRT= :WTIRWBRT,"
                    +"WTIRWGEWQM= :WTIRWGEWQM,"
                    +"WTIRWGEWLFD= :WTIRWGEWLFD,"
                    +"WTIRWMADI= :WTIRWMADI,"
                    +"WTIRWMADIM= :WTIRWMADIM,"
                    +"WTIRWMADIF= :WTIRWMADIF,"
                    +"WTIRWFDDI= :WTIRWFDDI,"
                    +"WTIRWFDDIM= :WTIRWFDDIM,"
                    +"WTIRWFDDIF= :WTIRWFDDIF,"
                    +"WTIRWGVERB= :WTIRWGVERB,"
                    +"WTIAGBRT= :WTIAGBRT,"
                    +"WTIAGGEWQM= :WTIAGGEWQM,"
                    +"WTIAGGEWLFD= :WTIAGGEWLFD,"
                    +"WTIAGMADI= :WTIAGMADI,"
                    +"WTIAGMADIM= :WTIAGMADIM,"
                    +"WTIAGMADIF= :WTIAGMADIF,"
                    +"WTIAGFDDI= :WTIAGFDDI,"
                    +"WTIAGFDDIM= :WTIAGFDDIM,"
                    +"WTIAGFDDIF= :WTIAGFDDIF,"
                    +"WTIAGGVERB= :WTIAGGVERB,"
                    +"WTIPGEWLFD= :WTIPGEWLFD,"
                    +"WTIPGEWQM= :WTIPGEWQM,"
                    +"WTIABWPGEW= :WTIABWPGEW,"
                    +"WTIUEBGEW= :WTIUEBGEW,"
                    +"WTIPMADI= :WTIPMADI,"
                    +"WTIPMADIM= :WTIPMADIM,"
                    +"WTIPMADIF= :WTIPMADIF,"
                    +"WTIABWPMADI= :WTIABWPMADI,"
                    +"WTIUEBMADI= :WTIUEBMADI,"
                    +"WTIFILLER= :WTIFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WTIMANDANT", OracleType.NVarChar).Value = dwData["WTIMANDANT"].ToString(); 
          or1.Parameters.Add("WTIKUNDNR", OracleType.NVarChar).Value = dwData["WTIKUNDNR"].ToString(); 
          or1.Parameters.Add("WTIWERK", OracleType.NVarChar).Value = dwData["WTIWERK"].ToString(); 
          or1.Parameters.Add("WTIABT", OracleType.NVarChar).Value = dwData["WTIABT"].ToString(); 
          or1.Parameters.Add("WTIART", OracleType.NVarChar).Value = dwData["WTIART"].ToString(); 
          or1.Parameters.Add("WTIVAR", OracleType.NVarChar).Value = dwData["WTIVAR"].ToString(); 
          or1.Parameters.Add("WTIAENZL", OracleType.NVarChar).Value = dwData["WTIAENZL"].ToString(); 
          or1.Parameters.Add("WTIAENB", OracleType.NVarChar).Value = dwData["WTIAENB"].ToString(); 
          or1.Parameters.Add("WTIAEND", OracleType.NVarChar).Value = dwData["WTIAEND"].ToString(); 
          or1.Parameters.Add("WTINEUB", OracleType.NVarChar).Value = dwData["WTINEUB"].ToString(); 
          or1.Parameters.Add("WTINEUD", OracleType.NVarChar).Value = dwData["WTINEUD"].ToString(); 
          or1.Parameters.Add("WTIPATRNR", OracleType.NVarChar).Value = dwData["WTIPATRNR"].ToString(); 
          or1.Parameters.Add("WTIAUFSTECK", OracleType.NVarChar).Value = dwData["WTIAUFSTECK"].ToString(); 
          or1.Parameters.Add("WTIBINDG", OracleType.NVarChar).Value = dwData["WTIBINDG"].ToString(); 
          or1.Parameters.Add("WTIDEHNQ", OracleType.NVarChar).Value = dwData["WTIDEHNQ"].ToString(); 
          or1.Parameters.Add("WTIDEHNL", OracleType.NVarChar).Value = dwData["WTIDEHNL"].ToString(); 
          or1.Parameters.Add("WTIRIPPSCHH", OracleType.NVarChar).Value = dwData["WTIRIPPSCHH"].ToString(); 
          or1.Parameters.Add("WTIPRUEFM", OracleType.NVarChar).Value = dwData["WTIPRUEFM"].ToString(); 
          or1.Parameters.Add("WTINAZAHL", OracleType.NVarChar).Value = dwData["WTINAZAHL"].ToString(); 
          or1.Parameters.Add("WTIFEINH", OracleType.NVarChar).Value = dwData["WTIFEINH"].ToString(); 
          or1.Parameters.Add("WTIFEINHGE", OracleType.NVarChar).Value = dwData["WTIFEINHGE"].ToString(); 
          or1.Parameters.Add("WTIABRT", OracleType.NVarChar).Value = dwData["WTIABRT"].ToString(); 
          or1.Parameters.Add("WTIWICKBRT", OracleType.NVarChar).Value = dwData["WTIWICKBRT"].ToString(); 
          or1.Parameters.Add("WTIARBSYS", OracleType.NVarChar).Value = dwData["WTIARBSYS"].ToString(); 
          or1.Parameters.Add("WTITOURSTK", OracleType.NVarChar).Value = dwData["WTITOURSTK"].ToString(); 
          or1.Parameters.Add("WTIRWBRT", OracleType.NVarChar).Value = dwData["WTIRWBRT"].ToString(); 
          or1.Parameters.Add("WTIRWGEWQM", OracleType.NVarChar).Value = dwData["WTIRWGEWQM"].ToString(); 
          or1.Parameters.Add("WTIRWGEWLFD", OracleType.NVarChar).Value = dwData["WTIRWGEWLFD"].ToString(); 
          or1.Parameters.Add("WTIRWMADI", OracleType.NVarChar).Value = dwData["WTIRWMADI"].ToString(); 
          or1.Parameters.Add("WTIRWMADIM", OracleType.NVarChar).Value = dwData["WTIRWMADIM"].ToString(); 
          or1.Parameters.Add("WTIRWMADIF", OracleType.NVarChar).Value = dwData["WTIRWMADIF"].ToString(); 
          or1.Parameters.Add("WTIRWFDDI", OracleType.NVarChar).Value = dwData["WTIRWFDDI"].ToString(); 
          or1.Parameters.Add("WTIRWFDDIM", OracleType.NVarChar).Value = dwData["WTIRWFDDIM"].ToString(); 
          or1.Parameters.Add("WTIRWFDDIF", OracleType.NVarChar).Value = dwData["WTIRWFDDIF"].ToString(); 
          or1.Parameters.Add("WTIRWGVERB", OracleType.NVarChar).Value = dwData["WTIRWGVERB"].ToString(); 
          or1.Parameters.Add("WTIAGBRT", OracleType.NVarChar).Value = dwData["WTIAGBRT"].ToString(); 
          or1.Parameters.Add("WTIAGGEWQM", OracleType.NVarChar).Value = dwData["WTIAGGEWQM"].ToString(); 
          or1.Parameters.Add("WTIAGGEWLFD", OracleType.NVarChar).Value = dwData["WTIAGGEWLFD"].ToString(); 
          or1.Parameters.Add("WTIAGMADI", OracleType.NVarChar).Value = dwData["WTIAGMADI"].ToString(); 
          or1.Parameters.Add("WTIAGMADIM", OracleType.NVarChar).Value = dwData["WTIAGMADIM"].ToString(); 
          or1.Parameters.Add("WTIAGMADIF", OracleType.NVarChar).Value = dwData["WTIAGMADIF"].ToString(); 
          or1.Parameters.Add("WTIAGFDDI", OracleType.NVarChar).Value = dwData["WTIAGFDDI"].ToString(); 
          or1.Parameters.Add("WTIAGFDDIM", OracleType.NVarChar).Value = dwData["WTIAGFDDIM"].ToString(); 
          or1.Parameters.Add("WTIAGFDDIF", OracleType.NVarChar).Value = dwData["WTIAGFDDIF"].ToString(); 
          or1.Parameters.Add("WTIAGGVERB", OracleType.NVarChar).Value = dwData["WTIAGGVERB"].ToString(); 
          or1.Parameters.Add("WTIPGEWLFD", OracleType.NVarChar).Value = dwData["WTIPGEWLFD"].ToString(); 
          or1.Parameters.Add("WTIPGEWQM", OracleType.NVarChar).Value = dwData["WTIPGEWQM"].ToString(); 
          or1.Parameters.Add("WTIABWPGEW", OracleType.NVarChar).Value = dwData["WTIABWPGEW"].ToString(); 
          or1.Parameters.Add("WTIUEBGEW", OracleType.NVarChar).Value = dwData["WTIUEBGEW"].ToString(); 
          or1.Parameters.Add("WTIPMADI", OracleType.NVarChar).Value = dwData["WTIPMADI"].ToString(); 
          or1.Parameters.Add("WTIPMADIM", OracleType.NVarChar).Value = dwData["WTIPMADIM"].ToString(); 
          or1.Parameters.Add("WTIPMADIF", OracleType.NVarChar).Value = dwData["WTIPMADIF"].ToString(); 
          or1.Parameters.Add("WTIABWPMADI", OracleType.NVarChar).Value = dwData["WTIABWPMADI"].ToString(); 
          or1.Parameters.Add("WTIUEBMADI", OracleType.NVarChar).Value = dwData["WTIUEBMADI"].ToString(); 
          or1.Parameters.Add("WTIFILLER", OracleType.NVarChar).Value = dwData["WTIFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
